const common = require('./webpack.common');
const {merge} = require('webpack-merge');
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin')


module.exports = merge(common, {
    mode: 'production',
    plugins: [
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin(
            {
                patterns: [
                {
                    from: path.resolve(__dirname, 'public/*.ico'),
                    to: 'public'
                }
            ]
            }
        ),
        new MiniCssExtractPlugin({
            filename: 'css/[name].[hash:8].css'
        })
    ],
    optimization: {
        minimizer: [
            new OptimizeCSSAssetsPlugin(),
            new TerserWebpackPlugin(),
        ]
    }
});